#include<stdio.h>
#include<conio.h>
int thang[1000],thua[1000],n=30,k;
void create(){
    thang[n]=1;
    thua[n]=0;
    for(int i=n-1;i>=1;i--){
        thang[i]=thua[i+1];
        thua[i]=thang[i+1];
        if(i*2<=n){
            thang[i]+=thua[i*2];
            thua[i]+=thang[i*2];
        }
    }
}
int next(int k){
    if(k*2>n)return k+1;
    if(thang[k+1]==0 && thua[2*k]==0)return 2*k;
    if(thang[2*k]==0 && thua[k+1]==0)return k+1;
    if(thang[2*k]-thua[2*k]>thang[k+1]-thua[k+1])return 2*k;
    else return 1+k;
}
int main(){
    printf("Nhap so n : ");scanf("%d",&n);
    printf("Nhap so a : ");scanf("%d",&k);
    do{
        printf("Hay chon so sau %d : ",k);
        scanf("%d",&k);
        if(k==n){
            printf("Nguoi thang ");
            break;
        }
        k=next(k);
        printf("\nMay chon %d ",k);
        if(k==n){
            printf("May thang ");
            break;
        }
    }while(k<=n);
    getch();
}
